/*
 */

/**
 * @author gsc
 * @description 用于更新state中的缓存对象，同时通过与localstorage想结合实现本地存储
 */
import {
  RECEIVE_USER_INFO,
	RECEIVE_CURRENT_ROLE,
	RECEIVE_SYSTEM_CONFIG,
	RECEIVE_MENUS,
	RECEIVE_LIST_SCROLL,
	RECEIVE_FILTER,
	RESET_USER_INFO,

} from './mutation-types'

export default {
	
	// 用户登录信息
	[RECEIVE_USER_INFO] (state, {userInfo}) {
		state.userInfo = userInfo
		localStorage.setItem('userInfo', JSON.stringify(userInfo))
	},
	// 用户当前角色
	[RECEIVE_CURRENT_ROLE] (state, {currentRoleName}) {
		state.currentRoleName = currentRoleName
		localStorage.setItem('currentRoleName', currentRoleName)
	},

	// 系统配置信息
	[RECEIVE_SYSTEM_CONFIG] (state, {systemConfig}) {
		state.systemConfig = systemConfig
		localStorage.setItem('systemConfig', JSON.stringify(systemConfig))
	},
	// 用户菜单
	[RECEIVE_MENUS] (state, {menus}) {
		state.menus = menus
		localStorage.setItem('menus', JSON.stringify(menus))
	},
	
	// 列表滚动位置
	[RECEIVE_LIST_SCROLL] (state, {listScroll}) {
		state.listScroll = listScroll
		localStorage.setItem('listScroll', listScroll)
	},

	// 注销登录
	[RESET_USER_INFO] (state) {
		state.userInfo = {}
		localStorage.removeItem('userInfo')
	},

	// 筛选项
	[RECEIVE_FILTER] (state, {filter, beanId}) {
		if(!state.filter) {
			state.filter = {}
		}
		state.filter[beanId] = filter
		let originFilter = JSON.parse(localStorage.getItem('filter'))
		if(!originFilter) {
			originFilter = {}
		}
		originFilter[beanId] = filter
		localStorage.setItem('filter', JSON.stringify(originFilter))
	}
}